package org.andes.kownledge.operator.executable;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import org.andes.kownledge.operator.Executable;
import org.andes.kownledge.operator.Predication;
import org.andes.kownledge.operator.Term;
import org.andes.sgg.Qsolver;
import org.andes.sgg.st;

public class WmOrDerive extends Executable{
	
//	;;; (wm-or-derive <goal>) checks if a goal can be satisfied by wm. If yes,
//	;;; successor states are the wm satisfiers alone; otherwise it attempts 
//	;;; to derive the goal by operators. This can be used for efficiency to 
//	;;; suppress needless search through operators in contexts where all we care 
//	;;; about is the result in wm.  Maybe needs a better name. Ensure-in-wm? 
//	(defun execute-wm-or-derive (Ex State)
//	  (or (goal-successors-wmes (second Ex) State t)
//	      (goal-successors-effects (second Ex) State)))
	@Override
	public List<st> exec(st state) {
		List<st> result=new ArrayList<st>();
		Stack<st> temp=Qsolver.instance.goal_successors_wmes((Predication) term,state,true);
		Stack<st> temp2=Qsolver.instance.goal_successors_effects((Predication) term,state);
		result.addAll(temp);
		result.addAll(temp2);
		return result;
	}

	Term term;
	public void setTerm(Term term){
		this.term=term;
	}
}
